<template>
    <div class="side-container">
        <el-input placeholder="请输入内容" v-model="input4">
            <i slot="prefix" class="el-input__icon el-icon-search"></i>
        </el-input>

        <el-menu default-active="0" class="el-menu-vertical-demo">
            <el-menu-item :index="String(index)" v-for="(item, index) in dutyList" :key="index">
                <i class="el-icon-menu"></i>
                <span slot="title">{{ item.title }}</span>
            </el-menu-item>
        </el-menu>

        <div class="gray-line" />

        <!-- 递归侧栏 -->
        <RecursionMenu :recursionList="floatList"/>
    </div>
</template>

<script>
import { syncRequest } from '@/utils/httpRequet'

import RecursionMenu from '../RecursionMenu/index.vue'

import treeData from './treeData.js'

export default {
    components: { RecursionMenu },
    props: {
        dutyList: { default: () => [] }
        // floatList: { default: () => [] }
    },
    filters: {
        handleTag(str) {
            const len = str.length
            return len > 2 ? str.substring(len - 2) : str
        }
    },
    data() {
        return {
            input4: '',
            value: false,
            // floatList: [
            //     { f_name: '我部门成员', isOpen: true, child: [] },
            //     { f_name: '我关注的部门', isOpen: true, child: [] },
            //     { f_name: '我关注的人员', isOpen: true, child: [] }
            // ],
            floatList: treeData,
            defaultOpeneds: [], // 是 el组件的index属性 ( 字符串 )
            defaultActiveStr: '0'
        }
    },
    mounted() {
        // this.init()
    },
    methods: {
        //初始化
        init() {
            //获取部门成员
            let pub_users = syncRequest({ url: 'pubGetDeptUsers', data: { deptId: '' } })
            if (pub_users.errorCode === '1') {
                this.floatList[0].child = JSON.parse(JSON.stringify(pub_users.data).replace(/userName/g, 'name'))
            }

            //获取关注部门
            let focus_dept = syncRequest({ url: 'pubGetFocusDept' })
            if (focus_dept.errorCode === '1') {
                this.attention_department = focus_dept.data
                this.attention_department = JSON.parse(JSON.stringify(this.attention_department).replace(/focusDeptName/g, 'name'))
                this.attention_department.forEach(res => {
                    this.$set(res, 'is_checked', false)
                })
                this.floatList[1].child = this.attention_department
            } else if (focus_dept.errorCode === '-5') {
                this.attention_department = []
            }

            //获取关注人
            let focus_user = syncRequest({
                url: 'pubGetFocusUser'
            })
            if (focus_user.errorCode === '1') {
                this.attention_men = focus_user.data
                this.attention_men = JSON.parse(JSON.stringify(this.attention_men).replace(/focusUserName/g, 'name'))
                this.attention_men.forEach(res => {
                    this.$set(res, 'is_checked', false)
                })
                this.floatList[2].child = this.attention_men
            } else if (focus_user.errorCode === '-5') {
                this.attention_men = []
            }

            console.log(this.floatList)
        }
    }
}
</script>

